package com.ssy.lingxi.member.merchant.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.DropdownItem;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 平台会员关系的外部状态枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2021-05-29
 */
public enum PlatformInnerStatusEnum {

    /**
     * 新增商户会员时的初始状态
     */
    REGISTERING(0, "申请注册", 0),

    /**
     * 待提交审核（新增、新注册后的初始状态） - 1
     */
    TO_BE_COMMIT(1, "待提交平台审核", 1),

    /**
     * 提交审核不通过 - 2
     */
    COMMIT_NOT_PASSED(2, "提交审核不通过",4),

    /**
     * 待审核(一级） - 3
     */
    TO_BE_VERIFY_STEP1(3, "待平台审核(一级)",2),

    /**
     * 一级审核不通过 - 4
     */
    VERIFY_STEP1_NOT_PASSED(4, "审核会员不通过(一级)",4),

    /**
     * 待审核(二级） - 5
     */
    TO_BE_VERIFY_STEP2(5, "待平台审核(二级)",3),

    /**
     * 二级审核不通过 - 6
     */
    VERIFY_STEP2_NOT_PASSED(6, "审核会员不通过(二级)",4),

    /**
     * 待确认审核 - 7
     */
    TO_CONFIRM(7, "待确认会员",0),

    /**
     * 审核不通过 - 8
     */
    VERIFY_NOT_PASSED(8, "平台审核不通过",0),

    /**
     * 审核通过 - 9
     */
    VERIFY_PASSED(9, "平台审核通过",0);


    /**
     * 内部状态
     */
    private final Integer code;

    /**
     * 对应报表服务的状态
     */
    private final Integer reportTypeCode;

    PlatformInnerStatusEnum(Integer code, String msg, Integer reportTypeCode) {
        this.code = code;
        this.reportTypeCode = reportTypeCode;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return LanguageHolder.getName(this.getClass(), this.getCode());
    }

    public Integer getReportTypeCode() {
        return reportTypeCode;
    }

    public static String getCodeMsg(Integer code) {
        return LanguageHolder.getName(PlatformInnerStatusEnum.class, code);
    }

    public static List<Integer> toList() {
        return Arrays.stream(PlatformInnerStatusEnum.values()).filter(value -> !value.getCode().equals(0)).map(PlatformInnerStatusEnum::getCode).collect(Collectors.toList());
    }

    public static PlatformInnerStatusEnum parse(Integer code) {
        return code == null ? null : Arrays.stream(PlatformInnerStatusEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
    }

    public static List<DropdownItem> toDropdownList() {
        return Arrays.stream(PlatformInnerStatusEnum.values()).sorted(Comparator.comparingInt(PlatformInnerStatusEnum::getCode)).map(e -> new DropdownItem(e.getCode(), e.getMsg())).collect(Collectors.toList());
    }
}
